package com.xing.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xing.dto.LiveTagDTO;
import com.xing.entity.LiveRoomEntity;
import com.xing.entity.LiveRoomTagEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LiveRoomTagDao extends BaseMapper<LiveRoomTagEntity> {


    @Select("select name\n" +
            "from live_tag\n" +
            "where id in (select lrt.tag_id from live_room_tag lrt where room_id = #{roomId})\n" +
            "  and del_flag = 0;")
    List<String> getRoomTagByRoomId(@Param("roomId") Long roomId);

    @Select("select *\n" +
            "from live_tag\n" +
            "where id in (select lrt.tag_id from live_room_tag lrt where room_id = #{roomId})\n" +
            "  and del_flag = 0;")
    List<LiveTagDTO> getRoomTagEntityByRoomId(@Param("roomId") Long roomId);

    @Delete("DELETE\n" +
            "FROM live_room_tag\n" +
            "WHERE room_id = (SELECT id\n" +
            "                 FROM live_room\n" +
            "                 WHERE anchor_id = #{anchorId})")
    void deleteByAnchorId(@Param("anchorId") Long anchorId);

}
